package com.learning;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@SpringBootApplication
public class Chapter5Java8dateApplication {

	public static void main(String[] args) {
		SpringApplication.run(Chapter5Java8dateApplication.class, args);
	}

	@RestController
	class HelloController{

		@PostMapping("/user")
		public UserDto user(@RequestBody UserDto dto){
			return dto;
		}
	}

	@Data
	@NoArgsConstructor
	@AllArgsConstructor
	static class UserDto{
		private String name;
		private LocalDate birthday;
	}


	//在配置了依赖之后，我们只需要在上面的应用主类中增加这个序列化模块，并禁用对日期以时间戳方式输出的特性
	@Bean
	public ObjectMapper serializingObjectMapper(){
		ObjectMapper objectMapper =  new ObjectMapper();
		objectMapper.disable(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS);
		objectMapper.registerModule(new JavaTimeModule());

		return objectMapper;
	}

}
